<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="linuxbox.bbs.logic.*" %>
<%@ page import="java.util.*" %>
<%@ page import="linuxbox.bbs.bean.BbsMsgKey" %>

<%@ taglib uri="/linuxbox/bbs.tld" prefix="bbs" %>

<%
  String CAT_ID = request.getParameter("CAT_ID");
  int iCatID = 0;
  if (CAT_ID == null || CAT_ID.equals(""))
    response.sendRedirect("../error.html");
  else
    iCatID = Integer.parseInt(CAT_ID);

  String sCatName = request.getParameter("CAT_NAME");

  String sQuery = request.getParameter("QUERY_TEXT");
  if (sQuery == null || sQuery.equals(""))
    response.sendRedirect("BbsContent?CAT_ID=" + iCatID);

  BbsManager bm = BbsManager.getInstance();
%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<SCRIPT LANGUAGE="Javascript">
function onChangeCategory()
{
    document.theForm.submit();
}
</SCRIPT>

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - BBS Search</b>
    </td>
<FORM action="<%=BoxStatic.servletDir%>BbsContentAction" method="POST" name="theForm" >
    <td ALIGN="right" valign="top">
      <a href="<%=BoxStatic.jspDir%>bbs/BbsNewList.jsp">New List</a>&nbsp;|&nbsp;

      <a href="<%=BoxStatic.jspDir%>bbs/BbsQueryAll.jsp">Search</a>

      &nbsp;|&nbsp;View Category
        <SELECT NAME="CAT_ID" onclick="onChangeCategory()">
          <bbs:BbsCatList listType="list" selected="<%=CAT_ID%>" />
        </select>
    </td>
</form>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=0 cellspacing=0>
  <tr><td>
    <table width="100%" border=0 cellpadding=0 cellspacing=0>
      <tr>
        <td>
          <a href="<%=BoxStatic.servletDir%>BbsProposeFormAction?CAT_ID=<%=iCatID%>">
            <img src="<%=BoxStatic.imageDir%>doc01.gif" alt="Propose New Message" border=0 width=32 height=32>
          </a>
          <a href="<%=BoxStatic.servletDir%>BbsContentAction?CAT_ID=<%=iCatID%>">
            <img src="<%=BoxStatic.imageDir%>doc02.gif" alt="BBS Content" border=0 width=32 height=32>
          </a>
        </td>

        <td align=right>
          <form action="<%=BoxStatic.jspDir%>bbs/BbsQuery.jsp" method="post">
            <input type="hidden" name="CAT_ID" value="<%=iCatID%>">
            <input type="hidden" name="CAT_NAME" value="<%=sCatName%>">
            <input type="text" size="20" name="QUERY_TEXT" value="<%=sQuery%>">
            <input type="submit" name="OK" value="Search">
          </form>
        </td>
      </tr>
    </table>
  </td></tr>
  <tr><td>
  <%
    try {
      BbsMsgKey key = null;
      BbsMsg msg = null;
      ArrayList keys = bm.queryByType(iCatID, 0, sQuery);

      int length = keys.size();
      if (length == 0)
      {
        out.print("No message found!");
      }
      else
      {
%>
    Search result of '<%=sQuery%>' in Category <%=sCatName%>:
    <TABLE cellSpacing=1 cellPadding=0 width="100%" border=0 bgColor=#dddddd>
      <tr bgcolor=#7EC1F3>
        <td><b>Time</b></td>
        <td><b>Author</b></td>
        <td><b>Subject</b></td>
      </tr>
  <%
        for (int i =0; i < length; i++)
        {
          key = (BbsMsgKey)keys.get(i);
          msg = bm.getBbsMsg(key);

          long lMsgID = msg.getID();
          String sAuthor = msg.getAuthor();
          java.sql.Date dtSubDate = msg.getSubDate();
          java.sql.Time tmSubTime = msg.getSubTime();
          String sSubject = msg.getSubject();

          String proptime = dtSubDate.toString() + " " + tmSubTime.toString();
          if (sSubject == null || sSubject.equals(""))
             sSubject = "(No subject)";
  %>

      <tr <% if ((i % 2) == 0) out.print("bgcolor=#f0f0f0"); %>>
      <td><%=proptime%></td>
      <td><%=sAuthor%></td>
      <td>
      <a href="<%=BoxStatic.servletDir%>BbsViewAction?CAT_ID=<%=iCatID%>&MSG_ID=<%=lMsgID%>"><%=sSubject%></a>
      </td>
      </tr>
  <%
        }
  %>
    </table>
  </td></tr>
  <tr><td>
    <table border=0 width="98%" cellpadding=0 cellspacing=0>
      <tr>
        <td>
          <a href="<%=BoxStatic.servletDir%>BbsProposeFormAction?CAT_ID=<%=iCatID%>">
          <img src="<%=BoxStatic.imageDir%>doc01.gif" alt="Propose New Message" border=0 width=32 height=32>
          </a>
          <a href="<%=BoxStatic.servletDir%>BbsContentAction?CAT_ID=<%=iCatID%>">
          <img src="<%=BoxStatic.imageDir%>doc02.gif" alt="BBS Content" border=0 width=32 height=32>
          </a>
        </td>
      </tr>
    </table>
  <%
      }
    } catch(Exception e) {
      System.out.println("Error : " + e.getMessage());
    }
  %>

  </td></tr>
</table>
<hr width=\"100%\" color=#E06000 align=left>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
